﻿using System;
using System.Collections.Generic;
using System.Linq;
using System.Web;
using System.Web.Mvc;
using RedSand.Web.Mvc;
using RedSand.Site.Models;
namespace RedSand.Site.Controllers
{
    public class ReplyController : BaseController
    {
        //
        // GET: /Reply/

        public ActionResult Index()
        {
            return View();
        }
        [AjaxOrChildAction]
        public ActionResult ListReply(int RequestId)
        {
            List<ReplyInfoFull> lst = new List<ReplyInfoFull>();
            lst = RsDataManager.GetList<ReplyInfoFull>("ReplyGetFullByRequestId", new { RequestId = RequestId });
            return PartialView(lst);
        }
        
        [AjaxOrChildAction]
        public ActionResult PostReply(ReplyInfo Info)
        {
            Info.UserID = UserID;
            Info.CreateDate = DateTime.Now;
            var InfoFull = new ReplyInfoFull();

            if (RsDataManager.Save("ReplySave", Info))
            {
                InfoFull.ReplyID = Info.ReplyID;
                InfoFull.RequestID = Info.RequestID;
                InfoFull.Content = Info.Content;
                InfoFull.CreateDate = Info.CreateDate;
                var PosterInfo = RsDataManager.GetInfo<UserInfo>("UserGetInfo", "UserId", UserID);
                InfoFull.Avatar = PosterInfo.Avatar;
                InfoFull.UserName = PosterInfo.Username;
            }
            return PartialView(InfoFull);
        }
    }
}
